网络安全第四次实验 陈实 SA17011008


1
SA17011008 陈实 2017年11月14日  实验 4

一、实验内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
32位Linux系统下的C函数如下:
void foo01()
{
char buff[16];
char Lbuffer[] = "01234567890123456789========ABCD";
strcpy (buff, Lbuffer);
}
void foo02()
{
char Lbuffer[] = "01234567890123456789========ABCD";
char buff[16];
strcpy (buff, Lbuffer);
}
用foo01()和foo02()替换buffer_overflow.c中的foo(), 通过GDB调试,
说明foo01()和foo02()是否存在缓冲区溢出漏洞。

二、实验环境

1
ubuntu 16.04

三、实验内容

##3.1 准备工作
①关闭地址随机化

1
sudo sysctl -w kernel.randomize_va_space=0

image.png-37.1kB
②关闭栈随机化设置

1
sudo  /sbin/sysctl -w kernel.randomize_va_space=0

image.png-15.8kB

##3.2 测试buffer_overflow.c
①编写并编译运行

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <string.h>
char Lbuffer[] = "01234567890123456789========ABCD";
void foo()
{
char buff[16];
strcpy (buff, Lbuffer);
}
int main()
{
foo();
return 0;
}

image.png-29kB

②GDB调试

1
2
3
gdb buf

r

image.png-104.7kB

③ 反编译main&foo

1
disas main

image.png-49.3kB

1
disas foo

image.png-55.8kB

##3.3 测试foo1()
①编写并编译运行foo1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
#include <string.h>

void foo1()
{
char buff[16];
char Lbuffer[] = "01234567890123456789========ABCD";
strcpy (buff, Lbuffer);
}
int main()
{
foo1();
return 0;
}

image.png-31.9kB

②调试
image.png-84.7kB
发生错误

##3.4 测试foo2()
①编写并编译运行foo2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>

#include <string.h>



void foo02()

{

char Lbuffer[] = "01234567890123456789========ABCD";

char buff[16];

strcpy (buff, Lbuffer);

}

int main()

{

foo02();

return 0;

}

image.png-24kB

②调试
image.png-95.9kB
未发生错误

#四、实验总结
通过本次实验,对缓冲区溢出攻击的原理有了更进一步的理解,需要更进一步的去了解shellcode原理与攻击。